package com.bocloud.cmp.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bocloud.cmp.entity.resource.CloudServer;
import com.bocloud.common.model.Param;
import com.bocloud.common.model.SimpleBean;
import com.bocloud.database.core.intf.GenericDao;

/**
 * 
 * 云主机 DAO接口
 * 
 * @author DZG
 * @since V1.0 2016年9月12日
 */
public interface CloudServerDao extends GenericDao<CloudServer, Long> {

	/**
	 * 查询云主机详细
	 * 
	 * @param id
	 *            the id
	 * @return the server
	 * @throws Exception
	 */
	public CloudServer get(Long id) throws Exception;

	/**
	 * 根据UUID查询
	 * 
	 * @param uuid
	 * @return
	 * @throws Exception
	 */
	public CloudServer getByUUID(String uuid) throws Exception;

	/**
	 * 根据serverId查询
	 * 
	 * @param serverId
	 * @return
	 * @throws Exception
	 */
	public CloudServer getByServerId(String serverId) throws Exception;

	/**
	 * 查询云主机列表
	 * 
	 * @param page
	 *            the page
	 * @param rows
	 *            the rows
	 * @param params
	 *            the params
	 * @param sorter
	 *            the sorter
	 * @return the result
	 * @throws Exception
	 */
	public List<CloudServer> list(int page, int rows, List<Param> params, Map<String, String> sorter) throws Exception;

	/**
	 * 查询所有
	 * 
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> list() throws Exception;

	/**
	 * 根据云云供应商ID查询
	 * 
	 * @param vendorId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByVendorId(Long vendorId) throws Exception;

	public List<CloudServer> listByVid(Long vendorId) throws Exception;

	/**
	 * 根据主机ID查询
	 * 
	 * @param hostId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByHid(Long hostId) throws Exception;

	/**
	 * 查询云主机简易列表
	 * 
	 * @param params
	 *            the params
	 * @param sorter
	 *            the sorter
	 * @return the bean
	 * @throws Exception
	 */
	public List<SimpleBean> list(List<Param> params, Map<String, String> sorter) throws Exception;

	/**
	 * 查询符合条件的数据数量
	 * 
	 * @param params
	 *            the params
	 * @return count
	 * @throws Exception
	 */
	public int count(List<Param> params) throws Exception;

	/**
	 * 删除云主机
	 * 
	 * @param id
	 *            the id
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean remove(Long id, Long userId) throws Exception;

	/**
	 * 根据云供应商ID删除
	 * 
	 * @param vendorId
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public boolean removeByVid(Long vendorId, Long userId) throws Exception;

	/**
	 * 检查name是否存在
	 * 
	 * @param name
	 *            the name
	 * @return
	 * @throws Exception
	 */
	public boolean exists(String name, Long vendorId) throws Exception;

	/**
	 * 通过IP获取服务器消息
	 * 
	 * @param ip
	 *            the manager ip
	 * @return
	 * @throws Exception
	 */
	public CloudServer get(String ip) throws Exception;

	/**
	 * 
	 * 根据名称查找虚拟机
	 * 
	 * @author DZG
	 * @since V1.0 2016年9月27日
	 */
	public CloudServer getByName(String name) throws Exception;

	/**
	 * 
	 * 根据用户ID查询实例名
	 * 
	 * @author liwending
	 * @since V1.0 2016年10月31日
	 */
	public List<CloudServer> list(Long userId, Date newDate) throws Exception;

	/**
	 * 根据VendorId和networkId查询
	 * 
	 * @param vendorId
	 * @param networkId
	 * @return
	 */
	public List<CloudServer> list(Long vendorId, String networkId) throws Exception;

	/**
	 * 根据配置ID查询
	 * 
	 * @param vendorId
	 * @param flavorId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByFid(Long vendorId, String flavorId) throws Exception;

	/**
	 * 根据镜像ID查询
	 * 
	 * @param vendorId
	 * @param imageId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByIid(Long vendorId, String imageId) throws Exception;

	/**
	 * 根据ID查询
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public CloudServer query(Long id) throws Exception;

	/**
	 * 查询所有的物理机
	 * 
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> queryAll() throws Exception;

	/**
	 * 获取所有虚拟机的uuid和ip
	 * <p>
	 * 使用SNMP自动发现采集对象时使用
	 * </p>
	 * 
	 * @author sxp
	 * @since V1.0 Dec 5, 2016
	 */
	public List<Map<String, String>> getAll4Snmp() throws Exception;

	/**
	 * 根据云供应商ID删除
	 * 
	 * @param vendorId
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public boolean removeByHost(Long hostId, Long userId) throws Exception;

	/**
	 * 根据你 hostName 和venderID查询
	 * 
	 * @param venderId
	 * @param hostName
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listvmByvhost(long venderId, String hostName) throws Exception;

	/**
	 * 数量
	 * 
	 * @param params
	 * @param type
	 * @return
	 * @throws Exception
	 */
	public int count(List<Param> params, String type) throws Exception;

	/**
	 * 根据宿主机更新虚拟机状态
	 * 
	 * @param hostId
	 * @param status
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public boolean updateStatusByHost(Long hostId, String status, Long userId, String original) throws Exception;

	/**
	 * 根据数据存储Id查询
	 * 
	 * @param storeId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByStore(Long storeId) throws Exception;

	/**
	 * 根据网络Id查询
	 * 
	 * @param networkId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByNetwork(Long networkId) throws Exception;
	
	/**
	 * 根据名称和vendorId查询虚拟机
	 * @param name
	 * @param vendorId
	 * @return
	 * @throws Exception
	 */
	public List<CloudServer> listByName(String name, Long vendorId) throws Exception;

}
